## 适用于多能级和单能级的get obserable,适合local observable，Energy，Var[H],不含Truncated_Weight
## 这里只是整理数据，数据都是MPS那边出来的
def get_obervable_v3(propstring, observablestr):  ## for any energy levels
    import numpy
    from copy import deepcopy
    eigen_measure_obs = pyalps.loadEigenstateMeasurements(
        result_files, what=[observablestr])
    ## 需要各组参数计算，都拥有相同数目的能级,依赖alps从低能级到高能级排
    observables = []
    num_levels = len(eigen_measure_obs[0][0].y)
    for i in range(num_levels):
        eigen_measure_obs_i = deepcopy(eigen_measure_obs)
        for j in eigen_measure_obs_i:
            j[0].y = np.array([j[0].y[i]])
        paras_vs_observables_i = pyalps.collectXY(
            eigen_measure_obs_i, x=propstring, y=observablestr)
        paras = paras_vs_observables_i[0].x
        observables_i = paras_vs_observables_i[0].y
        observables.append(observables_i)
    if num_levels == 1:
        observables = observables[0]
    observables = numpy.array(observables)
    return (paras, observables)

#(Ds, energy_variance) = get_obervable_v3('MAXSTATES', 'EnergyVariance')
##print(Ds)
#print('energy_variance is %s'%(energy_variance))
